import {post, request} from "../../request/index.js"
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    registerMsg:"",
    username:"",
    password:"",
    password2:"",
    sex:"",
    radios: [
      {
        label: '男',
        value: '男'
     },{
       label: '女',
       value: '女'
     }
    ],
  },
  userNameInput:function(e){
    this.setData({
      username: e.detail.value
    })
  },
  pwdInput:function(e){
    this.setData({
      password: e.detail.value
    })
  },

  radioChange: function(e) {
    this.setData({sex:e.detail.value})
  },
  pwdInput2:function(e){
    this.setData({
      password2: e.detail.value
    })
  },
  
  msgClear:function(e){
    this.setData({
      registerMsg: ""
    })
  },
  _register:function(options){
    const username= this.data.username;
    const password= this.data.password;
    const password2= this.data.password2;
    const sex= this.data.sex;
    if("" == username){
      this.setData({registerMsg:"请填写手机号"})
      return false;
    }
    if("" == password){
      this.setData({registerMsg:"请填写密码"})
      return false;
    }
    if(password.length<6||password.length>8){
      this.setData({registerMsg:"密码位数为6到8"})
      return false;
    }
    if("" == password2){
      this.setData({registerMsg:"请重复密码"})
      return false;
    }
    if(password != password2){
      this.setData({registerMsg:"两次密码填写不一致"})
      return false;
    }

    if(sex == ""){
      this.setData({registerMsg:"请选择性别"})
      return false;
    }
    const user = {};
    user.username = this.data.username;
    user.password = this.data.password;
    user.sex = this.data.sex;
    post({url:app.globalData.baseUrl+"sys_member/register",data:JSON.stringify(user)}).then(result=>{
       console.log('result',result.data)
       const res = result.data;
       if(res.code!=0){
         this.setData({registerMsg:res.message})
        }else{
          wx.navigateTo({
            url: '/pages/login/login',
          })
        }
     })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})